// house_pkg/pages/locate/index.ts
import QQMap from '../../../utils/qqmap'
Page({
  onLoad(){
    this.getLocation()
  },
  async getLocation(){
    const {latitude, longitude} =await wx.getLocation()
    this.getPoint(latitude, longitude)
  },
  async chooseLocation() {
    // 调用小程序 API 获取新的位置
    const {latitude, longitude} = await wx.chooseLocation()
    this.getPoint(latitude, longitude)
		
  },
  getPoint(latitude, longitude){
    QQMap.search({
      keyword: '酒吧', //搜索关键词
      location: [latitude, longitude].join(','), //设置周边搜索中心点
      page_size: 5,
      success: (result) => {
        // 过滤掉多余的数据
        const points = result.data.map(({ id, title, _distance }) => {
          return { id, title, _distance }
        })
        // 渲染数据
        console.log(points);
        this.setData({ points })
      }
    })
    QQMap.reverseGeocoder({
      location: [latitude, longitude].join(','),
      success:({ result: { address } })=>{
        this.setData({address})
      }
    })
  }
})